package com.tfswx.jcyw.sqlmodel.gic.function;

import com.googlecode.aviator.runtime.type.AviatorObject;
import com.googlecode.aviator.runtime.type.AviatorString;
import com.tfswx.jcyw.sqlmodel.api.function.RuntimeFuntion;

import java.util.List;
import java.util.Map;

/**
 * @author 张述江
 * @date 2024/03/09
 */
public class DefaultSumAndIf extends RuntimeFuntion {
    @Override
    public AviatorObject call(Map<String, Object> env, List<AviatorObject> args) {
        String arg1 = args.get(0).stringValue(env);
        String arg2 = args.get(1).stringValue(env);

        String str = "sum(if(" + arg1 + "," + arg2 + ",0))";
        return new AviatorString(str);
    }

    @Override
    public String getChineseName() {
        return "条件求和";
    }

    @Override
    public String getEnglishName() {
        return "sumAndIf";
    }
}
